//
//  LYSwiftMacro.swift
//  rrlWallet
//
//  Created by Gordon on 2017/8/2.
//  Copyright © 2017年 Gordon. All rights reserved.
//

import UIKit

// MARK: - ****** net config ******
public enum DevelopEnvironment {
    case zh             /// 测试环境    zh.
    case test(Int)      /// 测试环境    (Int).zh.
    case uat            /// UAT
    case online         /// 线上环境 
    case release(Int)   /// 发布  0 = A环境(正式上线)， 1 = B环境(预发布)
}

//zhangbotest
// let devConfig: DevelopEnvironment = .uat
//let devConfig: DevelopEnvironment = .test(1)
let devConfig: DevelopEnvironment = .release(0)
///  printf
func d_print(_ item: Any?) {
    #if DEBUG
    if let item = item {
        print(item)
    }
    #endif
}

var kIsOnlineEnvi: Bool {
    switch devConfig {
    case .release:
        return true
    default:
        return false
    }
}
var kAppJPushChannel: String {
    switch devConfig {
    case .release:
        return "AppStore"
    case .online:
        return "appOnlineTest"
    default:
        return "dev-test"
    }
}
var kAppUmChannel: String {
    switch devConfig {
    case .release:
        return "AppStore"
    case .online:
        return "appOnlineTest"
    default:
        return "dev-test"
    }
}
var kAppDevABVersion: String {
    switch devConfig {
    case .release(let num):
        return "\(num)"
    default:
        return "0"
    }
}

var kEarnUrl: String {
    switch devConfig {
    case .release:
        return "https://m.rrl360.com/"
    default:
        return "http://m.pengyuzhifeng.com/"
    }
}



// MARK: - ****** iPhone x nav适配 ******
func kNavBottom() -> CGFloat {
    if isIphoneX() {
        return 88
    }
    return 64
}

func kNavTop() -> CGFloat {
    if isIphoneX() {
        return 44
    }
    return 20
}

/// 刘海的高度
func kHairHei() -> CGFloat {
    if isIphoneX() {
        return 30
    }
    return 0
}

func kBtmSafeHei() -> CGFloat {
    if isIphoneX() {
        return 34
    }
    return 0
}

func kBtmTabBarHei() -> CGFloat {
    if isIphoneX() {
        return 34 + 49
    }
    return 49
}

func isIphoneX() -> Bool {
    return LYDevelopEx.shared.isIphonex
}

//func isSmallIphone() -> Bool {
//    return LYDevelopEx.shared.isSmallIphone
//}


func kAudioToolBarHei() -> CGFloat {
    return 50
}

// MARK: - ****** 尺寸相关 ******
// frame
func kFitWid(_ wid: CGFloat) -> CGFloat {
    return LYDevelopEx.shared.screenWidthRatio * wid
}

func kFitCWid(_ wid: CGFloat) -> CGFloat {
    return CGFloat(ceilf(Float(LYDevelopEx.shared.screenWidthRatio * wid)))
}

func kFitRWid(_ wid: CGFloat) -> CGFloat {
    return CGFloat(roundf(Float(LYDevelopEx.shared.screenWidthRatio * wid)))
}

func kRoundf(_ v: CGFloat) -> CGFloat {
    return CGFloat(roundf(Float(v)))
}

func kCeilf(_ v: CGFloat) -> CGFloat {
    return CGFloat(ceilf(Float(v)))
}

func kFloorff(_ v: CGFloat) -> CGFloat {
    return CGFloat(floorf(Float(v)))
}

func kFitFWid(_ wid: CGFloat) -> CGFloat {
    return CGFloat(floorf(Float(LYDevelopEx.shared.screenWidthRatio * wid)))
}

func kFitHei(_ Hei: CGFloat) -> CGFloat {
    return LYDevelopEx.shared.screenHeightRatio * Hei
}

func kFitCHei(_ Hei: CGFloat) -> CGFloat {
    return CGFloat(ceilf(Float(LYDevelopEx.shared.screenHeightRatio * Hei)))
}

func kFitFHei(_ Hei: CGFloat) -> CGFloat {
    return CGFloat(floorf(Float(LYDevelopEx.shared.screenHeightRatio * Hei)))
}

func kScreenWid() -> CGFloat {
    return LYDevelopEx.shared.screenWidth
}

func kScreenHei() -> CGFloat {
    return LYDevelopEx.shared.screenHeight
}

// MARK: - ****** 字体相关 ******
/*
 ======  FamilyName : PingFang SC ======
 === 1.  PingFangSC-Medium
 === 2.  PingFangSC-Semibold
 === 3.  PingFangSC-Light
 === 4.  PingFangSC-Ultralight
 === 5.  PingFangSC-Regular
 === 6.  PingFangSC-Thin
*/

func kLightFitFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: kFitRWid(size), weight: .light)
}

func kRegularFitFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: kFitRWid(size))
}

func kMediumFitFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: kFitRWid(size), weight: .medium)
}

func ksemiBoldFitFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: kFitRWid(size), weight: .semibold)
}

func kBoldFitFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: kFitRWid(size), weight: .bold)
}

func kStandardRegualrFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: size)
}

func kStandardMediumFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: size, weight: .medium)
}

func kStandardBoldFont(size: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: size, weight: .bold)
}

func kNaviFont() -> UIFont {
    return UIFont.systemFont(ofSize: 17)
}

func kNaviBtnFont() -> UIFont {
    return UIFont.systemFont(ofSize: 15)
}


// MARK: - ****** 其他 ******
// MARK: === ScrollIndicator 永远显示
let ly_alwaysShowScrollIndicator = 654321

//  AppStore 地址
func kAppStoreLink() -> String {
    return "https://itunes.apple.com/cn/app/id1372454072"
    /// http://url.cn/5jVlY49
}

// MARK: === 获取随机数
func kRandomNum(from: Int = 0, to: UInt32) -> Int {
    return Int(arc4random_uniform(to)) + from
}

// MARK: === 获取对象的地址
func kObjectAddress(_ obj: NSObject) -> String {
    return String.init(format: "%p", obj)
}

func kDelay(_ delay: Double, closure: @escaping () -> Void) {
    DispatchQueue.main.asyncAfter(
        deadline: .now() + delay, execute: closure)
}

func kMainAsync(closure: @escaping () -> Void) {
    DispatchQueue.main.async(execute: closure)
}


// MARK: - ********* notification name
let kFMCellDownloadPercentChanged = Notification.Name("kFMCellDownloadPercentChanged")
let kFileDownloadPercentChanged = Notification.Name("kFileDownloadPercentChanged")
